/*
 * @Author: shiweizhen 787632169@qq.com
 * @Date: 2025-07-01 14:17:16
 * @LastEditors: shiweizhen 787632169@qq.com
 * @LastEditTime: 2025-07-07 14:56:31
 * @Description:
 * Copyright (c) 2025-present HBIS Digital Technology Co.,Ltd. All rights reserved.
 */
import { default as request } from '@/framework/utils/request';
import { ID, ResultData } from 'hbisdt-design';
import {
  FilterType,
  SheetCalType,
  SheetPageType,
  UpdateCalType,
  UpdateResultType,
  UpdateWorkbookType
} from './types';

/**
 * 获取一个文件信息
 * @param id
 * @returns
 */
export const getWorkBookById = (id: ID) => {
  return request({
    method: 'GET',
    url: `/workbook/getById`,
    params: { id }
  });
};

/**
 * 表格数据更新
 * @param data
 * @returns
 */
export const updateWorkBookById = (data: UpdateWorkbookType) => {
  return request({
    method: 'POST',
    url: `/workbook/updateById`,
    data
  });
};

/**
 * 添加一个Sheet页
 * @param data
 * @returns
 */
export const addSheet = (data: SheetPageType) => {
  return request({
    method: 'POST',
    url: '/sheet/addSheet',
    data
  });
};

/**
 * 删除Sheet页
 * @param id
 * @returns
 */
export const delSheet = (id: string) => {
  return request({
    method: 'DELETE',
    url: '/sheet/delete',
    params: { id }
  });
};

/**
 * 获取计算结果
 * @param data
 * @returns
 */
export const saveSheetCal = (data: SheetCalType) => {
  return request({
    method: 'POST',
    url: '/sheetCal/save',
    data
  });
};

/**
 * 获取筛选数据
 * @param params
 * @returns
 */
export const filterSheet = (
  params: FilterType
): Promise<ResultData<{ label: string; value: number; id: number }[]>> => {
  return request({
    method: 'GET',
    url: '/sheetCal/filter',
    params
  });
};

/**
 * 更新Sheet的业务对象计算结果
 * @param params
 * @returns
 */
export const updateCalResult = (
  params: UpdateCalType
): Promise<ResultData<UpdateResultType[]>> => {
  return request({
    method: 'GET',
    url: '/sheetCal/updateResult',
    params
  });
};
